﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class admin_edconsulting : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        connection con = new connection();
        SqlConnection cn = con.connect();
        SqlCommand mySqlSelect = new SqlCommand("select * from Consulting where id = @id", cn);
        mySqlSelect.CommandType = CommandType.Text;
        SqlParameter paramid = new SqlParameter("@id", SqlDbType.BigInt);
        paramid.Value = Request.Params["id"];
        mySqlSelect.Parameters.Add(paramid);
        try
        {
            SqlDataReader rd = mySqlSelect.ExecuteReader();
            if (rd.HasRows)
            {
                rd.Read();
                des.Text = rd.GetSqlString(1).ToString();
            }
            rd.Close();
            cn.Close();
        }
        catch (Exception ex)
        {
            cn.Close();
            Console.WriteLine("Loi setValueFromDatabaseToForm : " + ex);
        }
    }

    protected void addbt_Click(object sender, EventArgs e)
    {
        connection con = new connection();
        SqlConnection cn = con.connect();
        SqlCommand mySqlSelect = new SqlCommand("update consulting set description = @des where id = @id", cn);
        mySqlSelect.CommandType = CommandType.Text;

        SqlParameter desc = new SqlParameter("@des", SqlDbType.NVarChar, 100);
        desc.Value = des.Text;

        SqlParameter id = new SqlParameter("@id", SqlDbType.BigInt);
        id.Value = Request.Params["id"];

        mySqlSelect.Parameters.Add(desc);
        mySqlSelect.Parameters.Add(id);
        mySqlSelect.ExecuteNonQuery();
        cn.Close();
        info.Text = "Bạn đã cập nhật thành công";
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx?page=qlconsulting");
    }
}